<!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
<stack>
<name>in</name>
<id>-1</id>
<cardCount>6</cardCount>
<cardID>2955</cardID>
<listID>7265</listID>
<cantModify><false /></cantModify>
<cantDelete><false /></cantDelete>
<cantAbort><false /></cantAbort>
<cardSize>
<width>640</width>
<height>480</height>
</cardSize>
<script>-- this script contains:-- WAIS globals and descriptions-- WAIS XFCNs to access the wais-listener-- general functions ( for parsing )-- some error handling functions-- note that the functions for parsing the source files-- have been moved to the background script-- address of the wais-listener comms structure handleglobal gWaisAddress-- wais folders to store sources, documents and questionsglobal WaisSourcesFolderglobal WaisDocumentsFolderglobal WaisQuestionsFolder-- document headline information globals ( per document )global docDatabaseNameglobal docSiteNameglobal docSiteIPglobal docSitePortglobal docScoreglobal docTypeglobal docLinesglobal docLengthglobal docBestMatchglobal docIDglobal docHeadline-- document headline rangeglobal docHeadlineRange-- document count global ( for current query )global docCount-- current document number globalglobal resultDocNum-- current document text handle and size ( if downloaded )global docHdlglobal docHdlSize-- source globals (used for reading source files)global siteNameglobal siteIPglobal sitePortglobal maintainerglobal databaseNameglobal databaseMaxDocNumglobal confidenceglobal description-- relevance feedback entry numberglobal relEntryNum-- diagsText globalglobal diagsText-- debug variable - when this is 1 then the stack puts up-- debug messages in the message windoidglobal DEBUG-- open sourcesglobal openSourceson openStack-- check the version of the OS-- this fails in any version of HC 2.1 or lessif the systemVersion < 7.0 thenanswer "You need System 7.0 to run this stack" with "OK"end if-- check the version of Hypercardif the version < 2.1 thenanswer "You need Hypercard 2.1 to run this stack" with "OK"end if-- check the amount of heap space we have-- we need 400K of heap space to run properlyif the heapSpace < 400000 thenanswer "There probably is not enough memory to run HyperWais"&¬" reliably, please allocate more memory to Hypercard" with "OK"end ifput checkFolders() into waisError-- debug variable - set to debugglobal DEBUGput 0 into DEBUG-- clear out list of currently opened sourcesglobal openSourcesput empty into openSources-- clear out some card fieldsput empty into background field "status_line"put empty into card field "query" of card "query"put empty into card field "feedback" of card "query"put empty into card field "results" of card "query"put empty into card field "document" of card "document"put empty into card field "start_line_count" of card "document"put empty into card field "end_line_count" of card "document"put empty into card field "total_line_count" of card "document"send mouseUp to button "New Source" of card "edit_sources"-- connect up and resetif OpenSession() = 0 thenif WaisResetSession() ≠ 0 thenanswer "Could not reset the wais-listener" with "OK"end ifelseanswer "Could not open a session to the wais-listener" with "OK"end ifend openStackon closeStack-- if the listener is open, reset it and close the connection-- reset and close the session from the wais-listenerif connected() = 1 thenif WaisResetSession() = 0 thenif CloseSession() ≠ 0 thenanswer "Could not close the session to the wais-listener" with "OK"end ifelseanswer "Could not reset the wais-listener" with "OK"end ifend ifend closeStackfunction OpenSession-- opens a sesson to the wais-listener, this sets the global-- gWaisAddress which is the handle to the apple events address-- structure which allows us to communicate with the wais-listener-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- connect up to the wais-listenerif disconnected() = 1 thenput "Opening session to wais listener" into background field "status_line"put HCOpenSession() into waisErrorif DEBUG = 1 thenput "OpenSession ("&gWaisAddress&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend OpenSessionfunction CloseSession-- closes a session to the wais-listener-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- disconnect from the wais-listenerif connected() = 1 thenput "Closing session to wais listener" into background field "status_line"put HCCloseSession(gWaisAddress) into waisErrorif DEBUG = 1 thenput "CloseSession ("&gWaisAddress&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend CloseSessionfunction OpenWaisSource databaseName, databaseMaxDocNum, ¬siteName, siteIP, sitePort-- this opens a connection to a wais source, all the parameters-- are mandatory-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- open a wais sourceif connected() = 1 thenput "Opening Wais source: "&databaseName into background field "status_line"put HCOpenWaisSource(gWaisAddress, databaseName, ¬databaseMaxDocNum, siteName, siteIP, sitePort) into waisErrorif DEBUG = 1 thenput "OpenWaisSource ("&databaseName&","&databaseMaxDocNum&","&¬siteName&","&siteIP&","&sitePort&") ["&waisError&"]" into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend OpenWaisSourcefunction CloseWaisSource databaseName, siteName, sitePort-- closes a connection to a wais source-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- close a wais sourceif connected() = 1 thenput "Closing Wais source: "&databaseName into background field "status_line"put HCCloseWaisSource(gWaisAddress, databaseName, ¬siteName, sitePort) into waisErrorif DEBUG = 1 thenput "CloseWaisSource ("&databaseName&","&¬siteName&","&sitePort&") ["&waisError&"]" into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend CloseWaisSourcefunction SubmitQuery queryText-- submits a query to all the currently opened wais sources-- this function returns when all the sources have been queried-- and all the results gathered-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- submit a query to all the open wais sourcesif connected() = 1 thenput "Searching Wais sources" into background field "status_line"put HCSubmitQuery(gWaisAddress, queryText) into waisErrorif DEBUG = 1 thenput "SubmitQuery ("&queryText&") ["&waisError&"]" into message boxend ifput handleDiagsText(diagsText) into dummyput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend SubmitQueryfunction GetDocCount-- gets the count of the number of documents in our result buffer-- and places it in the global variables docCount-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal docCountput 0 into waisErrorput 0 into docCount-- get the countif connected() = 1 thenput HCGetDocCount(gWaisAddress) into waisErrorput "Search complete, "&docCount&" hits" into background field "status_line"if DEBUG = 1 thenput "GetDocCount ("&docCount&") ["&waisError&"]" into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend GetDocCountfunction ReadQueryResult resultDocNum-- gets the document headline information from one of the documents-- in the result buffer, the document headline information retrieved-- corresponds to the resultDocNum passed (note that the document-- numbering starts at zero rather than 1)-- the data retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUG-- document headline information globalsglobal docDatabaseNameglobal docSiteNameglobal docSiteIPglobal docSitePortglobal docScoreglobal docTypeglobal docLinesglobal docLengthglobal docBestMatchglobal docIDglobal docHeadlineput 0 into waisError-- reset our document headline information globalsput empty into docDatabaseNameput empty into docSiteNameput empty into docSiteIPput 0 into docSitePortput 0 into docScoreput empty into docTypeput 0 into docLinesput 0 into docLengthput 0 into docBestMatchput empty into docIDput empty into docHeadline-- get the document headline informationif connected() = 1 thenput "Reading document information " into background field "status_line"put HCReadQueryResult(gWaisAddress, resultDocNum) into waisErrorif DEBUG = 1 thenput "ReadQueryResult ("&resultDocNum&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend ReadQueryResultfunction ReadQueryResultRange resultDocNumStart, resultDocNumEnd-- gets the document headline information from one of the documents-- in the result buffer, the document headline information retrieved-- corresponds to the resultDocNum passed (note that the document-- numbering starts at zero rather than 1)-- the data retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUG-- document headline rangeglobal docHeadlineRangeput 0 into waisError-- reset our document headline information globalsput empty into docHeadlineBlock-- get the document headline informationif connected() = 1 thenput "Reading document information " into background field "status_line"put HCReadQueryResultRange(gWaisAddress, resultDocNumStart,¬resultDocNumEnd) into waisErrorif DEBUG = 1 thenput "ReadQueryResultRange ("&resultDocNumStart&","&resultDocNumEnd&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend ReadQueryResultRangefunction GetDoc resultDocNum, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd-- downloads the document of type resultDocType from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document retrieved corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- the document retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsText-- document text handle and sizeglobal docHdlglobal docHdlSizeput 0 into waisError-- reset our document text handle and sizeput empty into docHdlput 0 into docHdlSize-- reset our diagsTextput empty into diagsText-- get the documentif connected() = 1 thenput "Getting document from Wais source" into background field "status_line"put HCGetDoc(gWaisAddress, resultDocNum, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "GetDoc ("&resultDocNum&","&resultDocType&","&resultChunkType&","&resultDocStart¬&","&resultDocEnd&") ["&waisError&"]" into message boxend ifput handleDiagsText(diagsText) into dummyput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend GetDocfunction GetDocByID databaseName, siteName, siteIP, sitePort, documentID, ¬resultDocType, resultChunkType, resultDocStart, resultDocEnd-- downloads the document specified by the documentID from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document retrieved is placed into the global variables listed belowglobal gWaisAddressglobal DEBUGglobal diagsText-- document text handle and sizeglobal docHdlglobal docHdlSizeput 0 into waisErrorput empty into diagsText-- reset our document text handle and sizeput empty into docHdlput 0 into docHdlSize-- get the document by IDif connected() = 1 thenput "Getting document from Wais source" into background field "status_line"put HCGetDocByID(gWaisAddress,databaseName, siteName,siteIP, ¬sitePort, documentID, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "GetDocByID ("&databaseName&","&siteName&","&siteIP&","&sitePort¬&","&documentID&","&resultDocType&","&resultChunkType¬&","&resultDocStart&","&resultDocEnd&") ["&waisError&"]" ¬into message boxend ifput handleDiagsText(diagsText) into dummyput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend GetDocByIDfunction GetDocToFile resultDocNum, resultDocType, docFileName, docFileCreator, ¬docFileType-- downloads the document to a file specified by docFileName and-- sets the file type and file creator to docFileType and docFileCreator-- respectively-- the whole document is downloaded-- the document retrieved corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- get the document and write it out to a fileif connected() = 1 thenput "Downloading document from Wais source to a file" into background field "status_line"put HCGetDocToFile(gWaisAddress, resultDocNum, resultDocType, ¬docFileName, docFileCreator, docFileType) into waisErrorif DEBUG = 1 thenput "GetDocToFile ("&resultDocType&","&resultDocNum&","&docFileName¬&","&docFileCreator &","&docFileType&") ["&waisError&"]" ¬into message boxend ifput handleDiagsText(diagsText) into dummyput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend GetDocToFilefunction GetDocToFileByID databaseName, siteName, siteIP, sitePort, documentID, ¬resultDocType, docFileName, docFileCreator, docFileType-- downloads the document specified by documentID to a file specified-- by docFileName and sets the file type and file creator to-- docFileType and docFileCreator respectively-- the whole document is downloaded-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- get the document by ID and write it out to a fileif connected() = 1 thenput "Downloading document from Wais source to a file" into background field "status_line"put HCGetDocToFileByID(gWaisAddress,databaseName, siteName, siteIP, ¬sitePort, documentID, resultDocType, docFileName, docFileCreator, ¬docFileType) into waisErrorif DEBUG = 1 thenput "GetDocByID ("&databaseName&","&siteName&","&siteIP&","&sitePort¬&","&documentID&","&resultDocType&","&docFileName¬&","&docFileCreator&","&docFileType&") ["&waisError&"]" ¬into message boxend ifput handleDiagsText(diagsText) into dummyput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend GetDocToFileByIDfunction RelFeedbackAdd resultDocNum, resultChunkType, resultDocStart, ¬resultDocEnd-- adds a document chunk to the relevance feedback array from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document chunk added corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- a relevance feedback entry number global is set to allow HC to track-- the entries in the array (the entry numbering starts at zero)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUG-- relevance feedback entry numberglobal relEntryNumput 0 into waisError-- reset the relevance feedback entry numberput empty into entryNum-- add an entry to the relevance feedback arrayif connected() = 1 thenput "Adding relevance feedback entry" into background field "status_line"put HCRelFeedbackAdd(gWaisAddress, resultDocNum, ¬resultChunkType, resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "HCRelFeedbackAdd ("&resultDocNum&","&resultChunkType¬&","&resultDocStart&","&resultDocEnd&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend RelFeedbackAddfunction RelFeedbackDel relEntryNum-- removes the entry from the relevance feedback array corresponding-- to the relEntryNum passed (the entry numbering starts at zero)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- delete an entry from the relevance feedback arrayif connected() = 1 thenput "Deleting relevance feedback entry" into background field "status_line"put HCRelFeedbackDel(gWaisAddress, relEntryNum) into waisErrorif DEBUG = 1 thenput "HCRelFeedbackDel ("&relEntryNum&") ["&waisError&"]" ¬into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend RelFeedbackDelfunction RelFeedbackClear-- clears out all the relevance feedback entries from the array-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- delete an entry from the relevance feedback arrayif connected() = 1 thenput "Clearing relevance feedback entry" into background field "status_line"put HCRelFeedbackClear(gWaisAddress) into waisErrorif DEBUG = 1 thenput "RelFeedbackClear ["&waisError&"]" into message boxend ifput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend RelFeedbackClearfunction WaisResetSession-- reset the session, closes all connections, clears out document result set and-- the relevance feedback array-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- reset the wais-listenerif connected() = 1 thenput "Reseting session" into background field "status_line"put HCWaisResetSession(gWaisAddress) into waisErrorif DEBUG = 1 thenput "WaisResetSession ["&waisError&"]" into message boxend if-- handle any errorsput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend WaisResetSessionfunction KillWaisListener-- terminates the wais-listener application-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGput 0 into waisError-- terminate the wais-listenerif connected() = 1 thenput "Quiting Wais Listener" into background field "status_line"put HCKillWaisListener(gWaisAddress) into waisErrorif DEBUG = 1 thenput "KillWaisListener ["&waisError&"]" into message boxend if-- handle any errorsput handleWaisError(waisError) into waisErrorput empty into background field "status_line"end ifreturn waisErrorend KillWaisListenerfunction MacUnBin srcFileName, destFileName, destFileCreator, ¬destFileType-- converts a file from MacBinary format to resource/data fork format-- a srcFileName must be specified, unless the other three parameters-- are specified, the XFCN will get them from the MacBinary file-- return error number ( 0 - no error )global DEBUG-- reset our waisErrorput 0 into waisErrorput "Converting file from MacBinary format" into background field "status_line"-- Unbinify our fileput HCMacUnBin(srcFileName, destFileName, destFileCreator, ¬destFileType) into waisErrorif DEBUG = 1 thenput "HCMacUnBin ("&srcFileName&","&destFileName&","&destFileCreator¬&","&destFileType&") ["&waisError&"]" into message boxend if-- handle any errorsput handleWaisError(waisError) into waisErrorput empty into background field "status_line"return waisErrorend MacUnBinfunction parseLine fieldLine, textLine-- parse out the second part of the line-- first replace the textLine with a null-- then replace the quotes with a null-- then replace the tabs with a null-- then trim the blanksput removeText(fieldLine, textLine ) into fieldLineput removeText(fieldLine, quote ) into fieldLineput removeText(fieldLine, tab ) into fieldLineput trimBlanks(fieldLine) into fieldLinereturn fieldLineend parseLinefunction removeText textLine, oldText-- this function removes every occurance of oldText in-- textLinerepeat until oldText is not in textLineput offset(oldText,textLine) into oldTextStartput "" into char oldTextStart to oldTextStart + ¬( the length of oldText - 1 ) of textLineend repeatreturn textLineend removeTextfunction trimBlanks textLine-- this function trims the leading and trailing blanks-- in textLine-- leading blanksput 1 into firstCharrepeatif character firstChar of textLine is space thenput firstChar + 1 into firstCharelseexit repeatend ifend repeatput character firstChar to ( the length of textLine ) ¬of textLine into textLine-- trailing blanksput ( the length of textLine ) into firstCharrepeatif character firstChar of textLine is space thenput firstChar - 1 into firstCharelseexit repeatend ifend repeatput character 1 to ( firstChar - 1 ) of textLine into textLinereturn textLineend trimBlanksfunction connected-- this function checks to see if we are connected to the wais-listener-- and returns 1 if we are and 0 if we are notglobal gWaisAddressif gWaisAddress is empty thenreturn 0elsereturn 1end ifend connectedfunction disconnected-- this function checks to see if we are disconnected from the wais-listener-- and returns 1 if we are and 0 if we are notglobal gWaisAddressif gWaisAddress is not empty and gWaisAddress ≠ 0 thenreturn 0elsereturn 1end ifend disconnectedfunction handleWaisError waisError, diagsText-- puts up an error messagereturn waisError-- handle the wais error number (optional)if waisError ≠ 0 thenanswer "Error in wais-listener: "&waisError with "OK"end if-- handle the diagsTextif diagsText is not empty thenanswer diagsText with "OK"end ifreturn waisErrorend handleWaisErrorfunction handleDiagsText diagsText-- puts up the diagnostics text returned from the-- wais server-- handle the diagsTextif diagsText is not empty thenanswer diagsText with "OK"end ifreturn 0end handleDiagsTextfunction checkFolders-- wais foldersglobal WaisSourcesFolderglobal WaisDocumentsFolderglobal WaisQuestionsFolder-- get our current preferencesput card field "wais-sources" of card "edit_preferences" into WaisSourcesFolderput card field "wais-documents" of card "edit_preferences" into WaisDocumentsFolderput card field "wais-questions" of card "edit_preferences" into WaisQuestionsFolder-- first check to see if these folders existif there is a folder WaisSourcesFolder thenput 1 into sourcesFolderOkelseput 0 into sourcesFolderOkend ifif there is a folder WaisDocumentsFolder thenput 1 into documentsFolderOkelseput 0 into documentsFolderOkend ifif there is a folder WaisQuestionsFolder thenput 1 into questionsFolderOkelseput 0 into questionsFolderOkend if-- grab the path name of the stackput word 2 of the long name of this stack into pathNameput the length of pathName - 1 into pathNameLengthput character 2 to pathNameLength of pathName into pathName-- grab the length of the name of the stackput word 2 of the name of this stack into stackNameput the length of stackName into stackNameLengthput pathNameLength - stackNameLength into pathNameLengthput character 1 to pathNameLength + 1 of pathName into pathNameif sourcesFolderOk = 0 thenput pathName & "wais-sources" into WaisSourcesFolderif there is a folder WaisSourcesFolder thenput WaisSourcesFolder into card field "wais-sources" ¬of card "edit_preferences"elseput empty into card field "wais-sources" ¬of card "edit_preferences"put empty into WaisSourcesFolderend ifend ifif documentsFolderOk = 0 thenput pathName & "wais-documents" into WaisDocumentsFolderif there is a folder WaisDocumentsFolder thenput WaisDocumentsFolder into card field "wais-documents" ¬of card "edit_preferences"elseput empty into card field "wais-documents" ¬of card "edit_preferences"put empty into WaisDocumentsFolderend ifend ifif questionsFolderOk = 0 thenput pathName & "wais-questions" into WaisQuestionsFolderif there is a folder WaisQuestionsFolder thenput WaisQuestionsFolder into card field "wais-questions" ¬of card "edit_preferences"elseput empty into card field "wais-questions" ¬of card "edit_preferences"put empty into WaisQuestionsFolderend ifend ifreturn 0end checkFolderson disallowInterruption -- so can't stop scripts while runningset cantAbort of this stack to trueend disallowInterruptionon allowInterruption -- so can stop scripts while runningset cantAbort of this stack to falseend allowInterruption</script>